package com.itmk.web.comments.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itmk.web.comments.entity.Comments;
import com.itmk.web.comments.mapper.CommentsMapper;
import com.itmk.web.comments.service.CommentsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments> implements CommentsService {

    @Autowired
    private CommentsMapper commentsMapper; // 引入 CommentsMapper

    // 根据 buyerId 获取评论，并且返回评论信息以及用户的头像和用户名
    public List<Comments> getCommentsByBuyerId(Long buyerId) {
        System.out.println(commentsMapper.getCommentsByBuyerId(buyerId));
        return commentsMapper.getCommentsByBuyerId(buyerId);
    }

    @Override
    public boolean isOrderCommented(Integer orderId) {
        // 查询该订单是否已存在评论
        int count = commentsMapper.countCommentsByOrderId(orderId);
        return count > 0; // 如果返回的 count 大于 0，表示已经有评论
    }


    // 根据 sellerId 获取评论，并且返回评论信息以及用户的头像和用户名
    public List<Comments> getCommentsBySellerId(Long SellerId) {

        return commentsMapper.getCommentsBySellerId(SellerId);
    }
}
